
#include <asm.h>

.global C_SYMBOL(ResizeBilinear_8u_P1)

C_SYMBOL(ResizeBilinear_8u_P1):

srcy_16= -0x48
y= -0x44
yrIntFloat_16= -0x40
xrIntFloat_16= -0x3C
DstPitch= -0x38
DstHeight= -0x34
DstWidth= -0x30
DstPt= -0x2C
SrcPitch = -0x1C
SrcHeight = -0x18
SrcWidth= -0x14
SrcPt= -0x10

    STMFD	SP!, {R4-R12,LR}
    SUB     SP, SP, #0x4C
Start:
//.long 0xe7fddefe
    LDR     R4, [R0,#0x0]
    STR     R4, [SP,#0x4C+SrcPt]

    LDR     R4, [R0,#0x4]
    STR     R4, [SP,#0x4C+SrcWidth]

    LDR     R4, [R0,#0x8]
    STR     R4, [SP,#0x4C+SrcHeight]

    LDR     R11, [R0,#0xC]
    STR     R11, [SP,#0x4C+SrcPitch]

    LDR     R9, [R1,#0x0]
    STR     R9, [SP,#0x4C+DstPt]

    LDR     R4, [R1,#0x4]
    STR     R4, [SP,#0x4C+DstWidth]

    LDR     R12, [R1,#0xC]
    STR     R12, [SP,#0x4C+DstPitch]

    SUB     R6, R12, R4

    LDR     R4, [R1,#0x8]
    STR     R4, [SP,#0x4C+DstHeight]

    //STR     R2, [SP,#0x4C+xrIntFloat_16]
    MOV     R7, R2
    STR     R3, [SP,#0x4C+yrIntFloat_16]

    LDR	R1, =0x00000008
    TMCRR   wR15 , R1, R1

    MOV	R3, #0

    STR	R3, [SP,#0x4C+srcy_16]

    LDR	R3, [SP,#0x4C+DstHeight]
    CMP	R3, #0
    BLS	Done

Header:

    LDR	R1, [SP,#0x4C+srcy_16]
    MOV	R3, R1,	LSL#16
    MOV R8, R3, LSR#24

    MOV	R2, R1,LSR#16

    LDR R3, [SP,#0x4C+SrcPt]
    MLA	R4, R2,	R11, R3

    LDR	R10, [SP,#0x4C+DstWidth]

    MOV R12, #0
    CMP	R10, #0

    MOV R0, R7, LSR #16

    BLE Done

LoopX:
@.long 0xe7fddefe

    MOV	R1, R12, LSL#16
    MOV	R1, R1, LSR#24        // R1 = u8 , R8 = v8

    MOV	    R2, R12,LSR#16
    ADD	    R2, R4, R2

    WLDRB wR3, [R2]
    WLDRB wR1, [R2, #1]
    ADD	R5, R2,	R11
    WLDRB wR2, [R5]
    WLDRB wR0, [R5, #1]

    ADD R2, R2, R0, LSL #3
    PLD	[R2]
    PLD	[R2,R11]

    TBCSTH  wR5, R1
    TBCSTH  wR6, R8

    WSUBH  wR0, wR0, wR2
    WMULUL wR0, wR0, wR5

    WSUBH  wR1, wR1, wR3
    WMULUL wR1, wR1, wR5

    WSLLH   wR2, wR2, wR15
    WSLLH   wR3, wR3, wR15

    WADDH   wR0, wR0, wR2
    WADDH   wR1, wR1, wR3

    WSRLH   wR0, wR0, wR15
    WSRLH   wR1, wR1, wR15

    WSUBH   wR0, wR0, wR1
    WMULUL  wR0, wR0, wR6
    WSLLH   wR1, wR1, wR15
    WADDH   wR0, wR0, wR1
    WSRLH   wR0, wR0, wR15
//    WPACKHUS wR0, wR0, wR1

    ADD R12, R12, R7

    SUBS R10, R10, #1

    WSTRB	wR0, [R9], #1

    BGT	LoopX

NextLine:
//.long 0xe7fddefe
    LDR	R1, [SP,#0x4C+srcy_16]
    LDR	R2, [SP,#0x4C+yrIntFloat_16]
    ADD	R1, R1,	R2
    STR	R1, [SP,#0x4C+srcy_16]

    MOV	R3, R1, LSL#16
    MOV R8, R3, LSR#24

    MOV	R2, R1,LSR#16

    LDR R3, [SP,#0x4C+SrcPt]
    ADD R9, R9, R6
    MLA	R4, R2,	R11, R3

    LDR	R10, [SP,#0x4C+DstWidth]
    LDR	R2, [SP,#0x4C+DstHeight]


    MOV R12, #0

    SUBS R2, R2, #1
    STR	R2, [SP,#0x4C+DstHeight]
    BGT  LoopX

Done:
    ADD	SP, SP,	#0x4C
    LDMFD	SP!, {R4-R12,PC}

